
$(document).ready(function(){
    var columns = eval(javaFns.getColumns());
    var data= eval(javaFns.getData());

//    var t = document.createElement('div');
//    t.style.height='300px';
    var table = createGrid(columns, data);
//    t.appendChild(table);
    document.body.appendChild(table);
    $(table).flexigrid({
        height:$(window).height()-26,
        resizable:false,
        singleSelect: true
    });
//    $(table).flexigrid();
});
function createGrid(columns, data){
    var table = document.createElement('table');
    var head = document.createElement('thead');
    var body = document.createElement('tbody');
    table.appendChild(head);
    table.appendChild(body);
    var tr = document.createElement('tr');
    head.appendChild(tr);
    for(var i in columns){
        var th = document.createElement('th');
        th.innerHTML = columns[i]['header'];
        th.dataIndex = columns[i]['dataIndex'];
        tr.appendChild(th);
    }
    for(var j in data){
        var tr = document.createElement('tr');
        body.appendChild(tr);
        for(var i in columns){
            var td = document.createElement('td');
            td.onclick = showDetails;
            td.val = data[j][columns[i]['dataIndex']];
            td.innerHTML = td.val;
            tr.appendChild(td);
        }
    }
    return table;
}
function showDetails(){
    console.log(a=this)
    javaFns.showToast(this.val);
}